<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
include_once(APPPATH."libraries/AdminController.php");
class Mata_uang extends AdminController {  
	function __construct()   
	{
		parent::__construct();    
		$this->_set_action();
		$this->_set_action(array("edit","delete"),"ITEM");
		$this->cat_search = array(
			'all'				=> 'Pilih Kategory',
			'cur_name'			=> 'Nama',
			'cur_code'			=> 'Kode Mata uang',
			'cur_value_per_rupiah'			=> 'Harga Per Rupiah'
		);
		$this->_set_title('Master > Mata Uang');
		$this->_set_cat_search(array("all"	=> $this->cat_search));	
		$this->DATA->table="tm_currency";
		$this->load->model("mdl_mata_uang","A");
		$this->folder_view = "ios/";
		$this->prefix_view = strtolower($this->_getClass());

	}

	function index(){
		
		$this->_set_desc_title('Daftar Mata Uang');	
		
		$this->data_table = $this->A->data( array(
				"limit" 	=> $this->per_page, 
				"offset" 	=> $this->uri->segment($this->uri_segment)
		) );
		
		$data = $this->_data(array(
				'base_url'		=> $this->own_link.'index'
			)
		);	
					
		$this->_v($this->folder_view.$this->prefix_view,$data);
	}
	
	function search(){
		$this->_set_desc_title('Daftar Mata Uang');	
		$this->load->helper('url');		
		$this->uri_segment = 6;
			
		$column = ''; $keyword = '';				
		if( isset($_POST['column']) && isset($_POST['keyword']) ){
			$column = $_POST['column'];
			$keyword = url_title($_POST['keyword']);
		}else{
			$column =  $this->uri->segment(4);
			$keyword =   $this->uri->segment(5);
		}	
			
		$this->data_table = $this->A->data( array(
								"limit" 	=> $this->per_page, 
								"offset" 	=> $this->uri->segment($this->uri_segment),
								"column"	=> $column,
								"keyword"	=> $keyword
							) );
		$data = $this->_data(
			array(
				'base_url'		=>$this->own_link.'search/'.$column.'/'.$keyword
			)
		);	
		
		
		$this->header_page['key']=$keyword;
		$this->header_page['col']=$column;	
		$this->header_page['cat_search'] = array($column	=>	$this->cat_search);	
		$this->_v($this->folder_view.$this->prefix_view,$data);
	}
	
	function add(){			
		$this->_set_desc_title('Tambah Mata Uang');		
		$this->_v($this->folder_view.$this->prefix_view."_form",array());
	}
	
	function edit($id=''){
		$id=dbClean(trim($id));
		$this->_set_desc_title('Update Data Mata Uang');	
		
		if(trim($id)!=''){
			$this->data_form = $this->DATA->data_id(array(
					'cur_id'	=> $id
				));
				
			$this->_v($this->folder_view.$this->prefix_view."_form",array());
		}else{
			redirect($this->own_link);
		}
	}
	
	function delete($id=''){
		$id=dbClean(trim($id));		
		if(trim($id) != ''){
			$o = $this->DATA->_delete(
				array("cur_id"	=> idClean($id))
			);
			
			$this->message = ($o)?_l('success_exec'):_l('fail_exec');
			
		}
		redirect($this->own_link);
	}

	function save(){
		$data = array(
			'cur_name'					=> dbClean($_POST['cur_name']),
			'cur_code'					=> dbClean($_POST['cur_code']),
			'cur_value_per_rupiah'		=> dbClean($_POST['cur_value_per_rupiah'])
		);		
		$a = $this->_save_master( 
			$data,
			array(
				'cur_id' => dbClean($_POST['cur_id'])
			),
			dbClean($_POST['cur_id'])			
		);
		redirect($this->own_link);
	}

}
